from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase = "DBshop010_退货管理处理退货流程"
# 进入前台，我的订单，已发货订单中复制一个订单号
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("已发货").click()
num=firefox.find_element_by_xpath("//table/thead/tr/th/div/a").text
print(num)
# 到退货申请,申请退货，输入订单号，退款原因，点击申请退货
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_link_text("点此申请退货").click()
firefox.find_element_by_id("order_sn").send_keys(num)
firefox.find_element_by_id("search-order").click()
firefox.find_element_by_id("refund_info").send_keys("无理由")
time.sleep(4)
firefox.find_element_by_xpath("//button[@class='btn btn-primary']").click()
time.sleep(4)
firefox.switch_to.alert.accept()
time.sleep(4)
firefox.quit()
#进入后台销售管理退货管理
firefox=openBrowser(url)
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,'销售管理','退货管理')
# 搜索该条订单的退货申请，处理退货，提取订单总额
firefox.find_element_by_xpath("//input[@class='span11']").send_keys(num)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
firefox.find_element_by_link_text("处理退货").click()
firefox.find_element_by_xpath("//select[@id='refund_state']/option[1]").click()
p=firefox.find_element_by_xpath("//font[contains(text(),'订单总额')]").text
l="订单总额:￥ "
r="$"
p1=int(reGetString(p,l,r))
# 输入处理方式、退款金额、处理意见，提交处理结果
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys(p1)
firefox.find_element_by_id("re_refund_info").send_keys("同意")
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
firefox.quit()
# 回到前台界面，点击“用户中心”，退货申请界面，查看退款成功
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text('用户中心').click()
firefox.find_element_by_link_text('退货申请').click()
time.sleep(2)
firefox.find_element_by_name("search_content").send_keys(num)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
time.sleep(2)
# 断言:该订单的状态显示退款成功即测试通过
t=firefox.find_element_by_xpath("//table/tbody/tr/td[4]").text
if t=="退款成功":
    writeLog("%s 测试通过"%testCase)
else:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
